package  
{
	import flash.events.MouseEvent;
	import flash.text.TextField;
	/**
	 * ...
	 * @author patsup
	 * 
	 * 		The class for each individual pirate.  The PirateLocation class holds the
	 * 	vector data for its PirateUnits, and PirateLocation handles the swapping and
	 * 	removal of their own PirateUnits.
	 * 
	 * *** public functions
	 * Initialize():void
	 * SwapLocations():void
	 * GetNumber():int
	 * 
	 * *** protected functions
	 * InitImage():void
	 * InitInput():void
	 * InputMouseClick(e:MouseEvent):void
	 * 
	 */
	public class PirateUnit extends Button 
	{
		private var pirateLoc:PirateLocation;				 //location of pirate (lineup or plank)
		private var pirateNumber:int;
		
		//temporary pirate image parameters
		private const PIRATE_COLOR:int = 0xFF80C0;
		private const PIRATE_WIDTH:int = 26;
		private const PIRATE_HEIGHT:int = 36;
		private var numLabel:TextField;
		
		public function PirateUnit(pirateLoc:PirateLocation, pirateNumber:int, xCoord:int, yCoord:int) 
		{
			name = "Pirate_" + String(pirateNumber);
			this.pirateLoc = pirateLoc;
			this.pirateNumber = pirateNumber;

			numLabel = new TextField();		//for the temporary txt label
			
			Initialize();
			super(xCoord, yCoord);
		}
		
		//Initialize()
		//Initializes the creation of the PirateUnit
		public override function Initialize():void
		{
			InitImage();
			//InitInput();
			
			super.Initialize();
		}
		
		//InitImage()
		//Initializes the image of the PirateUnit
		protected override function InitImage():void
		{
			graphics.beginFill(PIRATE_COLOR);
			graphics.drawRect(0, 0, PIRATE_WIDTH, PIRATE_HEIGHT);
			graphics.endFill();
			
			//Use TextField() to label pirate with its pirateNumber
			numLabel.text = String(pirateNumber);
			//numLabel.border = true;
			numLabel.width = numLabel.textWidth*2;			//reduce the textfield's dimensions so they don't inflate the stage
			numLabel.height = numLabel.textHeight*1.5;
			numLabel.x = 0.5 * PIRATE_WIDTH - 0.5 * numLabel.width;
			numLabel.y = 0.5 * PIRATE_HEIGHT - 0.5 * numLabel.height;
			addChild(numLabel);								//now add this txt label to the display list
			
			super.InitImage();
		}
		
		//InitInput()
		//Initializes the input for mouseclicks on PirateUnit
		protected override function InitInput():void
		{
			//mainStage.addEventListener(KeyboardEvent.KEY_DOWN, InputKeyboardDown);
			super.InitInput();
		}
		
		//InputMouseClick()
		//Takes action for PirateUnit upon hearing the mouseclick event
		//Move between PirateLineup and PiratePlank
		protected override function InputMouseClick(e:MouseEvent):void
		{
			pirateLoc.PirateMove(this);					//Tell this pirate location i'm moving so it can handle adding/remove childs and vectors
			super.InputMouseClick(e);
		}
		
		//SwapLocations()
		//switch this pirate's location (called from pirateLocation) between lineup and plank
		//pirateLocation holds the actual Vector data of where the pirates are and handles the visibility
		public function SwapLocations():void
		{
			pirateLoc = pirateLoc.GetOtherLocation();
		}
		
		//GetNumber()
		//Return the Pirate's Number
		public function GetNumber():int
		{
			return pirateNumber;
		}
	}

}